﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using OnlineVideos.Data;
using Common.Library;
using OnlineVideos.UI;
using OnlineVideos.ViewModels;
using System.Windows.Threading;

namespace VideoMix.Views
{
    public partial class DetailPage : PhoneApplicationPage
    {
        DispatcherTimer timer = new DispatcherTimer();
        public DetailPage()
        {
            InitializeComponent();
            Loaded += DetailPage_Loaded;
        }

        void DetailPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                timer.Interval = new TimeSpan(200);
                timer.Tick += timer_Tick;
                timer.Start();
                if (Constants.navigationfrom == "FavoriteShows")
                {
                    pvtMainDetails.SelectedIndex = 0;
                    Constants.navigationfrom = string.Empty;
                }
                else
                    pvtMainDetails.SelectedIndex = 1;
                performanceProgressBar.IsIndeterminate = true;
                tblkVideosTitle.Text = OnlineShow.GetShowDetail(Convert.ToInt32(AppSettings.ShowID)).Title.ToUpper();
                performanceProgressBar.IsIndeterminate = false;
              
            }
            catch (Exception ex)
            {
                
              
            }
        }

        void timer_Tick(object sender, EventArgs e)
        {

            if (VideoList.lbxSongsList.Items.Count == 0 && Constants.VisiablehelpImage==true)
            {
                ImgHelpLine.Visibility = Visibility.Visible;
                Constants.VisiablehelpImage = false;
                timer.Stop();
            }
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {

            if (AppSettings.bcount)
            {
                if (NavigationService.CanGoBack)
                    NavigationService.GoBack();
                //TODO: Use the onBackKeyPress in RatingPopup
                //ratingPopup.close();
            }

            AppSettings.detailtocast = 0;
            //if (YouTube.CancelPlay())
            //    e.Cancel = true;

            base.OnBackKeyPress(e);
        }

        private void appbariconaddvideos_Click_1(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/BrowserPage.xaml", UriKind.Relative));
        }

        private void appbariconplayvideomix_Click_1(object sender, EventArgs e)
        {
            History h = new History();
            h.SaveMovieHistory(AppSettings.ShowID, AppSettings.ShowID);
            NavigationService.Navigate(new Uri("/Views/PlayVideoMixPage.xaml", UriKind.Relative));
        }

        private void pvtMainDetails_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            switch ((sender as Pivot).SelectedIndex)
            {
                case 0:
                    this.ApplicationBar = this.Resources["appBarfordetailpivot"] as ApplicationBar;
                    break;
                case 1:
                    this.ApplicationBar = this.Resources["appBarforvideopivot"] as ApplicationBar;
                    break;
                default:
                    break;
            }
           
        }
        public void videocount()
        {
            ImgHelpLine.Visibility = Visibility.Collapsed;
        }
        private void appbariconedit_Click_1(object sender, EventArgs e)
        {
            NavigationService.Navigate(NavigationHelper.CreatePlayListPage);
            Constants.UpdatePlayListTitleAndDescrption = true;
        }

        private void share_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/userSharePage.xaml", UriKind.Relative));
        }

        private void sharevideomix_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/userSharePage.xaml", UriKind.Relative));
        }

        private void ImgHelpLine_MouseLeftButtonDown_1(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            NavigationService.Navigate(NavigationHelper.getHelpDetailPage("5", "SphD6zFQcew"));
        }

       
    }
}